﻿﻿@model WebApp.Models.WaterManualRecord
<!-- 弹出编辑窗体表单 -->
<div id="watermanualrecorddetailwindow" class="easyui-window"
     title="编辑抄表记录"
     data-options="modal:true,
                    closed:true,
                    minimizable:false,
                    collapsible:false,
                    maximized:false,
                    iconCls:'fal fa-window',
                    onRestore:function(){
                    },
                    onMaximize:function(){
                    }
                    " style="width:800px;height:450px;display:none">
  <!-- toolbar -->
  <div class="panel-content py-2 rounded-bottom border-faded border-left-0 border-right-0  text-muted bg-subtlelight-fade sticky-top">
    <div class="d-flex justify-content-end pr-4">
      <div class="btn-group btn-group-sm mr-1">
        <button name="saveitembutton" class="btn btn-default">
          <i class="fal fa-save"></i> @Html.L("Save")
        </button>
      </div>
      <div class="btn-group btn-group-sm mr-1" id="deleteitem-btn-group">
        <button name="deleteitembutton" class="btn btn-danger">
          <i class="fal fa-trash-alt"></i> @Html.L("Delete")
        </button>
      </div>
    </div>
  </div>
  <!-- panel container form  -->
  <div class="panel-container show">
    <div class="container">
      <div class="panel-content">
        <form id="watermanualrecord_form"
              class="easyui-form form-horizontal padding-10"
              method="post" novalidate>
          @Html.AntiForgeryToken()
          <!--Primary Key-->
          @Html.HiddenFor(model => model.Id)
          <fieldset class="form-group">
            <div class="row h-100 align-items-center">

              <!--表号-->
              <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"> @Html.DisplayNameFor(model => model.meterId)</label>
              <div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">
                <input id="@Html.IdFor(model => model.meterId)"
                       name="@Html.NameFor(model => model.meterId)"
                       value="@Html.ValueFor(model => model.meterId)"
                       tabindex="1"
                       class="easyui-combogrid"
                       style="width:100%"
                       type="text"
                       data-options="prompt:'@Html.DisplayNameFor(model => model.meterId)',
								                 required:false,
                                 textField:'meterId',
                                 idField:'meterId',
                                 panelWidth: 500,
                                 method: 'get',
                                 pagination:true,
                                 mode: 'remote',
                                 remoteFilter: true,
                                 clientPaging: false,
                                 columns: [[
                                    {field:'meterId',title:'表号',width:100},
                                    {field:'Name',title:'表名',width:120},
                                    {field:'LineNo',title:'表序号',width:80},
                                    {field:'Name1',title:'出线名称',width:160},
                                    {field:'CustomerName',title:'使用单位',width:160},
                                 ]],
                                 fitColumns: true,
                                 validType: 'length[0,20]',
                                 onSelect:function(index,row){
                                   $('#watermanualrecord_form #Name').textbox('setValue',row.Name);
                                   $('#watermanualrecord_form #LineNo').textbox('setValue',row.LineNo);
                                   $('#watermanualrecord_form #Name1').textbox('setValue',row.Name1);
                                   $('#watermanualrecord_form #LastWater').textbox('setValue',row.LastWater);
                                   $('#watermanualrecord_form #LastRecordDate').datebox('setValue',row.LastWaterDate);
                                 }
                                 " />
              </div>

              <!--表名-->
              <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"> @Html.DisplayNameFor(model => model.Name)</label>
              <div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">
                <input id="@Html.IdFor(model => model.Name)"
                       name="@Html.NameFor(model => model.Name)"
                       value="@Html.ValueFor(model => model.Name)"
                       tabindex="1"
                       class="easyui-textbox"
                       style="width:100%"
                       type="text"
                       data-options="prompt:'@Html.DescriptionFor(model => model.Name)',
								 required:false,readonly:true,
                                 validType: 'length[0,50]'
                                 " />
              </div>


              <!--表序号-->
              <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"> @Html.DisplayNameFor(model => model.LineNo)</label>
              <div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">
                <input id="@Html.IdFor(model => model.LineNo)"
                       name="@Html.NameFor(model => model.LineNo)"
                       value="@Html.ValueFor(model => model.LineNo)"
                       tabindex="2"
                       class="easyui-textbox"
                       style="width:100%"
                       type="text"
                       data-options="prompt:'@Html.DescriptionFor(model => model.LineNo)',
								 required:false,readonly:true,
                                 validType: 'length[0,50]'
                                 " />
              </div>

              <!--出线名称-->
              <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"> @Html.DisplayNameFor(model => model.Name1)</label>
              <div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">
                <input id="@Html.IdFor(model => model.Name1)"
                       name="@Html.NameFor(model => model.Name1)"
                       value="@Html.ValueFor(model => model.Name1)"
                       tabindex="3"
                       class="easyui-textbox"
                       style="width:100%"
                       type="text"
                       data-options="prompt:'@Html.DescriptionFor(model => model.Name1)',
								 required:false,readonly:true,
                                 validType: 'length[0,50]'
                                 " />
              </div>


              <!--本期读数-->
              <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"><span class="text-danger">*</span> @Html.DisplayNameFor(model => model.Water)</label>
              <div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">
                <input id="@Html.IdFor(model => model.Water)"
                       name="@Html.NameFor(model => model.Water)"
                       value="@Html.ValueFor(model => model.Water)"
                       tabindex="4"
                       class="easyui-numberbox"
                       style="width:100%"
                       type="text"
                       data-options="prompt:'@Html.DescriptionFor(model => model.Water)',
								 required:true,formatter:numberformatter,
                                 parser:parsernumber,precision:2,

                                 " />

              </div>

              <!--抄表日期-->
              <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"><span class="text-danger">*</span> @Html.DisplayNameFor(model => model.RecordDate)</label>
              <div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">
                <input id="@Html.IdFor(model => model.RecordDate)"
                       name="@Html.NameFor(model => model.RecordDate)"
                       value="@Html.ValueFor(model => model.RecordDate)"
                       tabindex="5" required
                       class="easyui-datebox"
                       style="width:100%"
                       type="text"
                       data-options="prompt:'@Html.DescriptionFor(model => model.RecordDate)',
								 required:true,
								 formatter:dateformatter" />
              </div>


              <!--备注-->
              <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"> @Html.DisplayNameFor(model => model.Remark)</label>
              <div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">
                <input id="@Html.IdFor(model => model.Remark)"
                       name="@Html.NameFor(model => model.Remark)"
                       value="@Html.ValueFor(model => model.Remark)"
                       tabindex="6"
                       class="easyui-textbox"
                       style="width:100%"
                       type="text"
                       data-options="prompt:'@Html.DescriptionFor(model => model.Remark)',
								 required:false,
                                 validType: 'length[0,250]'
                                 " />
              </div>

            </div>
          </fieldset>
        </form>
      </div>
    </div>
  </div>
</div>

<!-- 弹出窗体form表单 -->
<!-- 弹出编辑对话框 -->
<!--begin popup detailview javascript block -->
<script type="text/javascript">
  //当初始的 HTML 文档被完全加载和解析完成之后
  document.addEventListener('DOMContentLoaded', function () {
    //绑定按钮事件
    $('button[name="saveitembutton"]').on('click', savewatermanualrecorditem);
    $('button[name="deleteitembutton"]').on('click', deletewatermanualrecorditem);
  });
  //判断新增编辑状态
  var MODELSTATE = 'Added';
  var watermanualrecordid = null;
  function openwatermanualrecorddetailwindow(data, state) {
    MODELSTATE = state;
    //判断是否显示功能按钮
    if (MODELSTATE === 'Added') {
      $('#deleteitem-btn-group').hide();
    } else {
      $('#deleteitem-btn-group').show();
    }
    initwatermanualrecorddetailview();
    watermanualrecordid = (data.Id || 0);
    $('#watermanualrecorddetailwindow').window('open');
    $('#watermanualrecord_form').form('reset');
    $('#watermanualrecord_form').form('load', data);

    var url = '/WaterMeters/GetComboGridData';
    $('#watermanualrecord_form #meterId').combogrid('grid').datagrid('load', url);
  }
  //删除当前记录
  function deletewatermanualrecorditem() {
    $.messager.confirm('确认', '你确定要删除该记录?', result => {
      if (result) {
        const url = `/WaterManualRecords/Delete/${watermanualrecordid}`;
        $.get(url).done(res => {
          if (res.success) {
            toastr.success("删除成功");
            $('#watermanualrecorddetailwindow').window('close');
            reloadData();
          } else {
            $.messager.alert('错误', res.err, 'error');
          }
        });
      }
    });
  }
  //async 保存数据
  async function savewatermanualrecorditem() {
    const $watermanualrecordform = $('#watermanualrecord_form');
    if ($watermanualrecordform.form('enableValidation').form('validate')) {
      let watermanualrecord = $watermanualrecordform.serializeJSON();
      let url = '/WaterManualRecords/Edit';
      //判断是新增或是修改方法
      if (MODELSTATE === 'Added') {
        url = '/WaterManualRecords/Create';
      }
      var token = $('input[name="__RequestVerificationToken"]', $watermanualrecordform).val();
      $.ajax({
        type: "POST",
        url: url,
        data: {
          __RequestVerificationToken: token,
          watermanualrecord: watermanualrecord
        },
        dataType: 'json',
        contentType: 'application/x-www-form-urlencoded; charset=utf-8'
      })
        .done(response => {
          if (response.success) {
            hook = false;
            $watermanualrecordform.form('disableValidation');
            $watermanualrecordform.form('submitChanged');
            $('#watermanualrecorddetailwindow').window("close");
            toastr.success("保存成功");
            reloadData();
          } else {
            $.messager.alert("错误", response.err, "error");
          }
        })
        .fail((jqXHR, textStatus, errorThrown) => {
          $.messager.alert('异常', `${jqXHR.status}: ${jqXHR.statusText} `, 'error');
        });
    }
  }
  //判断是否有没有保存的记录
  function watermanualrecordhasmodified() {
    return hook;

  }


  function initwatermanualrecorddetailview() {
    //回车光标移动到下个输入控件
    //如果是枚举类型需要把numberbox改成combobox
    //本期读数
    $('#Water').numberbox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
    //日期类型 抄表日期
    $('#RecordDate').datebox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
  }
</script>

